package org.doubango.FrCall.Screens;

import java.util.ArrayList;
import java.util.HashMap;

import org.doubango.FrCall.Engine;
import org.doubango.FrCall.R;
import org.doubango.FrCall.Services.IScreenService;

import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import android.widget.AdapterView.OnItemClickListener;

public class ScreenHistoryCall extends BaseScreen {
	
	private static final String TAG = BaseScreen.class.getCanonicalName();
	private final IScreenService mScreenService;
	
	private Button backToContactsView;
	private ListView historyCallList;
	
	public ScreenHistoryCall() {
		super(SCREEN_TYPE.HISTORY_CALL, TAG);
		mScreenService = ((Engine)Engine.getInstance()).getScreenService();
	}

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.screen_history_call);
		
		backToContactsView = (Button) findViewById(R.id.back_to_contacts_view);
		historyCallList = (ListView) findViewById(R.id.list_history_call);
		
		backToContactsView.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				mScreenService.show(ScreenContactsPage.class);
			}
		});
		HashMap<String, String> historyCallMap = new HashMap<String, String>();
		historyCallMap.put("callName", "马福顺");
		historyCallMap.put("callNumber", "13567985243");
		historyCallMap.put("callTime", "一天前");
		ArrayList<HashMap<String, String>> historyCallData = new ArrayList<HashMap<String,String>>();
		for(int i=0;i<10;i++){
			historyCallData.add(historyCallMap);
		}
		SimpleAdapter historyCallAdapter = new SimpleAdapter(this, historyCallData, R.layout.history_call_item, new String[]{"callName","callNumber","callTime"}, new int[]{R.id.history_call_name,R.id.history_call_number,R.id.history_call_time});
		historyCallList.setAdapter(historyCallAdapter);
		historyCallList.setOnItemClickListener(new OnItemClickListener() {
			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
					long arg3) {
				Intent intent = new Intent(ScreenHistoryCall.this ,DialPage.class);
				startActivity(intent);
//				contactsFlipper.setDisplayedChild(1);
			}
		});
	}

}
